#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1.5e6+5,inf=1e9,mods=1e9+7;
namespace tr
{
	struct node
	{
		signed lson,rson,laz,sm;
	} p[N*40];
	int idx;
	void upset(int x)
	{
		p[x].sm=(p[p[x].lson].sm+p[p[x].rson].sm)%mods;
	}
	void mul(int x,int sm)
	{
		p[x].laz=1ll*p[x].laz*sm%mods;
		p[x].sm=1ll*p[x].sm*sm%mods;
	}
	void dnset(int x)
	{
		if(p[x].laz!=1)
		{
			mul(p[x].lson,p[x].laz);
			mul(p[x].rson,p[x].laz);
			p[x].laz=1;
		}
	}
	int nw()
	{
		idx++;
		p[idx].laz=1;
		return idx;
	}
	void init(int x)
	{
		if(!p[x].lson)p[x].lson=nw();
		if(!p[x].rson)p[x].rson=nw();
	}
	void mul(int x,int l,int r,int sm,int nl,int nr)
	{
		if(!x)return;
		if(l<=nl&&r>=nr)
		{
			mul(x,sm);
			return;
		}
		int mid=nl+nr>>1;
		dnset(x);
		if(l<=mid)mul(p[x].lson,l,r,sm,nl,mid);
		if(r>mid)mul(p[x].rson,l,r,sm,mid+1,nr);
		upset(x);
	}
	void add(int x,int d,int sm,int nl,int nr)
	{
		if(nl==nr)
		{
			p[x].sm+=sm;
			p[x].sm%=mods;
			return;
		}
		int mid=nl+nr>>1;
		init(x);
		dnset(x);
		if(d<=mid)add(p[x].lson,d,sm,nl,mid);
		else add(p[x].rson,d,sm,mid+1,nr);
		upset(x);
	}
	int gets(int x,int l,int r,int nl,int nr)
	{
		if(!x)return 0;
		if(l<=nl&&r>=nr)return p[x].sm;
		int mid=nl+nr>>1;
		dnset(x);
		if(r<=mid)return gets(p[x].lson,l,r,nl,mid);
		if(l>mid)return gets(p[x].rson,l,r,mid+1,nr);
		return (gets(p[x].lson,l,r,nl,mid)+gets(p[x].rson,l,r,mid+1,nr))%mods;
	}
}
int n,k,zt,dp[N],zd[N],cd[N],g[N],mk[N],res,hz[N],dlt[N],zx[N],rt[N];
vector<int>p[N];
void dfs0(int x)
{
	mk[x]=1;
	for(int i=0; i<p[x].size(); i++)
	{
		int c=p[x][i];
		if(mk[c])continue;
		dfs0(c);
		if(zd[c]+1>zd[x])zd[x]=zd[c]+1,zx[x]=i;
	}
	if(zx[x])
	{
		swap(p[x][zx[x]],p[x][0]);
		zx[x]=p[x][zx[x]];
	}
	mk[x]=0;
}
void dfs1(int x)
{
	mk[x]=1;
	cd[x]=-inf;
	zd[x]=0;
	for(auto c:p[x])
	{
		if(mk[c])continue;
		dfs1(c);
		if(zd[c]+1>zd[x])cd[x]=zd[x],zd[x]=zd[c]+1,zx[x]=c;
		else if(zd[c]+1>cd[x])cd[x]=zd[c]+1;
	}
	int nw=0;
	for(int i=p[x].size()-1; i>=0; i--)
	{
		int c=p[x][i];
		if(mk[c])continue;
		hz[c]=nw;
		nw=max(nw,zd[c]+1);
	}
	mk[x]=0;
}
void dfs2(int x)
{
	mk[x]=1;
	for(auto c:p[x])
	{
		if(mk[c])continue;
		if(zd[c]+1==zd[x])g[c]=max(g[x]+1,cd[x]+1);
		else g[c]=max(g[x]+1,zd[x]+1);
		dfs2(c);
	}
	mk[x]=0;
}
void add(map<int,int>&q,int l,int r,int sm)
{
	if(l>r)return;
	q[l]+=sm;
	q[r+1]-=sm;
	q[l]%=mods;
	q[r+1]%=mods;
}
void mul(int x,int l,int r,int sm)
{
	if(l>r)return;
	tr::mul(rt[x],l+dlt[x],r+dlt[x],sm,-n,n);
}
int gets(int x,int l,int r)
{
	if(l>r)return 0;
	return tr::gets(rt[x],l+dlt[x],r+dlt[x],-n,n);
}
void add(int x,int d,int sm)
{
	tr::add(rt[x],d+dlt[x],sm,-n,n);
}
void dfs(int x)
{
	mk[x]=1;
	int nw=0,mx=0;
	dp[x]=1;
	if(zx[x])
	{
		int c=zx[x];
		dfs(c);
		map<int,int>tmp;
		int tdp=0;
		int R=min(mx,k-zd[c]-2);
		if(0<=R)tmp[0]+=dp[c]%mods;
		if(zd[c]+g[c]>=k-1)
		{
			if(nw+max(g[x],hz[c])<k-1)tmp[0]+=gets(c,k-1,zd[c]);
			else if(k-1<=zd[c])tmp[0]+=gets(c,k-1,k-1);
		}
		else
		{
			if(nw+max(g[x],hz[c])<k-1)tmp[0]+=gets(c,max(k-1-max(g[x],hz[c]),0ll),zd[c]);
			else if(k-1<=zd[c])tmp[0]+=gets(c,k-1,k-1);
			tmp[0]+=gets(c,0,min(k-max(g[x],hz[c])-2,zd[c]));
		}
		if(zd[c]+1+max(g[x],hz[c])<k-1||max(g[x],hz[c])<k-1)
		{
			rt[x]=rt[c];
			dlt[x]=dlt[c];
			mul(x,min(zd[c],k-nw-2)+1,zd[c],0);
			dlt[x]--;
		}
		else
		{
			rt[x]=rt[c];
			dlt[x]=dlt[c];
			mul(x,0,max(nw,k-max(g[x],hz[c])-1)-1,0);
			mul(x,min(zd[c],k-nw-2)+1,zd[c],0);
			dlt[x]--;
		}
		mx=max(mx,zd[c]+1);
		if(nw+zd[c]+1<k-1)tdp+=dp[x]*dp[c]%mods;
		for(auto c:tmp)add(x,c.first,c.second);
		tdp%=mods;
		dp[x]=tdp;
		nw=max(nw,zd[c]+1);
	}
	else rt[x]=tr::nw(),add(x,0,1);
	for(auto c:p[x])
	{
		if(mk[c])continue;
		dfs(c);
		map<int,int>q,tmp;
		int tdp=0;
		for(int i=0; i<=min(zd[c],k-nw-2); i++)
		{
			int ans=dp[x]*gets(c,i,i)%mods;
			if(i+1+max(g[x],hz[c])>=k)
			{
				if(nw>=i+1)continue;
			}
			else if(zd[c]+1+max(g[x],hz[c])>=k-1)
			{
				if(nw+max(g[x],hz[c])>=k-1)continue;
			}
			if(zd[c]+1>nw)tmp[i+1]+=ans;
			else tdp+=ans;
		}
		int R=min(mx,k-zd[c]-2);
		if(0<=R)tmp[0]+=gets(x,0,0)*dp[c]%mods;
		if(zd[c]+1>nw)
		{
			tdp+=dp[c]*gets(x,max(zd[c]+2,k-max(g[x],hz[c])),R)%mods;
		}
		else
		{
			add(q,max(zd[c]+2,k-max(g[x],hz[c])),R,dp[c]);
		}
		if(nw+max(g[x],hz[c])<k-1||zd[c]+1+max(g[x],hz[c])<k-1)
		{
			if(zd[c]+1>nw)
			{
				tdp+=dp[c]*gets(x,1,min(k-max(g[x],hz[c])-1,R))%mods;
			}
			else
			{
				add(q,1,min(k-max(g[x],hz[c])-1,R),dp[c]);
			}
		}
		for(int j=0; j<=zd[c]; j++)
		{
			int R=min(mx,k-j-1),L=0;
			if(k-j-1<0)continue;
			if(nw+zd[c]+1>=k-1)L=max(L,k-j-1);
			if(j+1<k&&zd[c]+g[c]>=k-1)L=max(L,1ll);
			if(j+1+max(g[x],hz[c])>=k)
			{
				if(j+1==k||nw+max(g[x],hz[c])<k-1)
				{
					if(L==0)tmp[0]+=gets(x,0,0)*gets(c,j,j)%mods;
				}
			}
			else
			{
				if(zd[c]+1>nw)
				{
					if(L==0)tmp[0]+=gets(c,j,j);
				}
				else
				{
					add(q,L,min(R,j),gets(c,j,j));
				}
			}
			if(j+1>=L&&j+1<=R)tmp[j+1]+=gets(x,j+1,j+1)*gets(c,j,j)%mods;
			int mid=k-max(g[x],hz[c]);
			if(zd[c]+1+max(g[x],hz[c])<k-1)
			{
				add(q,max({j+2,L,mid}),R,gets(c,j,j));
			}
			if(zd[c]+1>nw)
			{
				tmp[j+1]+=gets(c,j,j)*gets(x,max(j+2,L),min(R,mid-1))%mods;
			}
			else
			{
				add(q,max(j+2,L),min(R,mid-1),gets(c,j,j));
			}
		}
		mx=max(mx,zd[c]+1);
		if(nw+zd[c]+1<k-1)tdp+=dp[x]*dp[c]%mods;
		int nws=0,lst=0;
		for(auto c:q)
		{
			mul(x,lst,c.first-1,nws);
			lst=c.first;
			nws+=c.second;
			nws%=mods;
		}
		mul(x,lst,mx,nws);
		for(auto c:tmp)add(x,c.first,c.second);
		tdp%=mods;
		dp[x]=tdp;
		nw=max(nw,zd[c]+1);
	}
}
signed main()
{
	freopen("life.in","r",stdin);
	freopen("life.out","w",stdout);
	int maxnnn=0;
	cin>>n>>k;
	for(int i=1; i<n; i++)
	{
		int x,y;
		cin>>x>>y;
		p[x].push_back(y);
		p[y].push_back(x);
	}
	for(int i=1;i<=n;i++) maxnnn=max(maxnnn,(int)(p[i].size()));
	if(maxnnn>=3&&n>18) return 0;
	dfs0(1);
	dfs1(1);
	dfs2(1);
	dfs(1);
	res=dp[1];
	for(int i=0; i<=zd[1]; i++)res+=gets(1,i,i);
	res%=mods;
	if(res)cout<<"YES\n"<<(res+mods)%mods;
	else cout<<"NO\n0";
}

